@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
@endsection
@section('content')
    <div class="content">
        <div class="header">

            <h1 class="page-title">pt后台管理</h1>
            <ul class="breadcrumb">
                <li>banner管理</li>
                <li class="active">学院banner列表</li>
                 <!-- <li class="active">标签列表</li> -->
            </ul>

        </div>
        <div class="main-content">

            <div class="btn-toolbar list-toolbar">
                <form class="form-inline" action="" method="get">
                    <!-- <a href="/banner/add" class="btn btn-primary"><i class="fa fa-plus"></i> banner</a> -->
                      <div class="form-group">
                        <input type="text" class="form-control" name="keyword" placeholder="编号或目标">
                      </div>
                      <div class="form-group">
                        <select class="form-control" name="state">
                          <option value="">状态</option>
                          <option value="1">已处理</option>
                          <option value="0">未处理</option>
                        </select>
                      </div>
                      <button type="submit" class="btn btn-default">筛选</button>
                </form>
            </div>

            <div class="row">
                <div class="col-sm-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading no-collapse">标签列表<!-- <span class="label label-warning">+10</span> --></div>
                        <table class="table table-bordered table-striped">
                          <thead>
                            <tr>
                                <th width="5%">编号</th>
                                <th width="10%">课程标题</th>
                                <th width="15%">学习目标</th>
                                <th width="10%">微信号</th>
                                <th width="5%">状态</th>
                                <th width="5%">添加时间</th>
                                <th width="10%">操作</th>
                            </tr>
                          </thead>
                          <tbody>

                            @foreach($list as $item)
                            <tr>
                              <td>{{$item['id']}}</td>
                              @if($item->courseclass)
                              <td>{{$item->courseclass->title}}</td>
                              @else
                              <td>课程不存在</td>
                              @endif
                              <td>{{$item['targets']}}</td>
                              <td>{{$item['wechat_number']}}</td>
                              <td>
                                @if($item['state']==1)
                                <span class="label label-success" id="is_handle{{$item['id']}}">已处理</span>
                                @else
                                <span class="label label-danger" id="is_handle{{$item['id']}}">未处理</span>
                                @endif 
                              </td>
                              <td>{{$item->created_at}}</td>
                              <td>
                                @if($item['state']==1)
                                <a href='javascript:;' data-id="{{$item['id']}}" data-true="1" class="is_handle">已确认</a>
                                @else
                                <a href='javascript:;' data-id="{{$item['id']}}" data-true="0" class="is_handle">确认</a>
                                @endif
                              </td>
                            </tr>
                            @endforeach
                          </tbody>
                        </table>
                    </div>
                   
                </div>
            </div>
            {{$list->appends(['keyword'=>$keyword,'state'=>$state])->render()}}
            <div class="modal small fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h3 id="myModalLabel">Delete Confirmation</h3>
                        </div>
                        <div class="modal-body">
                            <p class="error-text"><i class="fa fa-warning modal-icon"></i>Are you sure you want to delete the user?<br>This cannot be undone.</p>
                        </div>
                        <div class="modal-footer">
                            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
                            <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    
    <script type="text/javascript">
        $(document).ready(function(){
            //提交信息
            $("#submit_form_add").click(function(){
                var data = $("#tag_form_add").serialize();
                data = decodeURIComponent(data,true);
                $.ajax({
                    type:"POST",
                    url:"/tags/addtag",
                    data:data,
                    dataType:'json',
                    success:function(result){
                        console.log(result);
                        if(result.code==1){
                            location.reload();
                        }else{
                            alert(result.msg);
                        }
                    }
                });
            });

            $(".is_handle").click(function(){
                var id      = $(this).attr("data-id");
                var is_true = $(this).attr("data-true");
                var state   = 1;
                var token   = '{{csrf_token()}}';
                var is_handle = "is_handle"+id;
                if(is_true==1){
                  alert("已处理，无需重复操作");
                  return;
                }
                $.ajax({
                    type:"GET",
                    url:"/course/consultstate",
                    data:{id:id, state:state},
                    dataType:'json',
                    success:function(result){
                        if(result.code==1){
                          alert(result.msg);
                          $("#"+is_handle).text("已处理");
                          $("#"+is_handle).attr("class", "label label-success");
                        }else{
                          alert(result.msg);
                        }
                    }
                });
            });

            $("#submit_form_edit-").click(function(){
                var data1 = $("#tag_form_edit").serialize();
                data1 = decodeURIComponent(data1,true);
                $.ajax({
                    type:"POST",
                    url:"/tags/addtag",
                    data:data1,
                    dataType:'json',
                    success:function(result){
                        console.log(result);
                        if(result.code==1){
                            location.reload();
                        }else{
                            alert(result.msg);
                        }
                    }
                });
            });    

        })
    </script>
@endsection